<template>
<view class="container">
    <view class="navbar">
        <view v-for="(item, index) in categories" :key="index" class="navbar-box">
            <view :id="item.type" :class="activeType == item.type ? 'navbar-item-on' : ''" @tap="changeTab">
                {{item.name}}
            </view>
        </view>
    </view>
    <view class="point-box">
        <view class="point-item title">描述</view>
        <view class="point-item title">积分</view>
        <view class="point-item title">时间</view>
    </view>
    <view v-for="(item, index) in points" :key="index" class="point-box">
        <view class="point-item">{{item.desc}}</view>
        <view class="point-item price">{{item.pay_points}}</view>
        <view class="point-item time">{{item.changeTimeFommat}}</view>
    </view>
</view>
</template>

<script>
var app = getApp();
import LoadMore from "../../../utils/LoadMore";
var load = new LoadMore();
var util = require("../../../utils/util.js");

export default {
  data() {
    return {
      url: app.globalData.setting.url,
      resourceUrl: app.globalData.setting.resourceUrl,
      categories: [{
        name: "全部",
        type: 'all'
      }, {
        name: "赚取",
        type: 'plus'
      }, {
        name: "消费",
        type: 'minus'
      }],
      activeType: 'all',
      points: null,
      currentPage: 1
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    var type = typeof options.type == 'undefined' ? this.activeType : options.type;
    load.init(this, '', 'points');
    this.requestPointList(type);
  },
  onReachBottom: function () {
    if (load.canloadMore()) {
      this.requestPointList(this.activeType);
    }
  },
  onPullDownRefresh: function (e) {
    this.points = null;
    this.currentPage = 1;
    load.resetConfig();
    this.requestPointList(this.activeType);
  },
  methods: {
    changeTab: function (e) {
      //重置数据
      load.resetConfig();
      this.points = null;
      this.currentPage = 1;
      this.requestPointList(e.currentTarget.id);
    },
    requestPointList: function (type) {
      var that = this;
      var requestUrl = '/api/user/points_list/type/' + type + '?p=' + that.currentPage;
      this.setData({
        activeType: type
      });
      load.request(requestUrl, function (res) {
        that.currentPage++;
        res.data.result.forEach(function (val, index, arr) {
          val.changeTimeFommat = util.format(val.change_time, 'yyyy-MM-dd hh:mm');
        });
        uni.stopPullDownRefresh();
      });
    }
  }
};
</script>
<style>
page{
    background-color: #fff;
}
.container{
    padding: 20rpx 20rpx;
}
.navbar{
    width: 100%;
}
.navbar-box{
    font-size: 30rpx;
    display: inline-block; 
    width:33.333333%;
    box-sizing: border-box;
    text-align: center;
    line-height:85rpx;
}
.navbar-item-on{
    font-size: 35rpx;
    position: relative;
    color: #ff6a00;
}
.navbar-item-on:after{
    content:'';
    position: absolute;
    width:40rpx;
    height:8rpx;
    background:linear-gradient(90deg,rgba(255,59,59,1) 0%,rgba(255,115,61,1) 100%);
    border-radius:4rpx;
    left: 50%;
    margin-left: -20rpx;
    bottom: 0rpx;
}
.top-box{
  background: #F0F0F0;
  font-size: 26rpx;
  color: #666666;
  width: 100%;
  padding: 20rpx 0;
  margin-top: 30rpx;
  border-radius: 10rpx;
}
.point-box{
    width: 100%;
    font-size: 28rpx;
    padding: 20rpx 0;
    border-radius: 10rpx;
    /* padding-left: 5rpx; */
}
.point-box:nth-child(odd){
    background: #fff;
}
.point-box:nth-child(even){
    background: #FAFAFA;
}
.point-item{
    display: inline-block; 
    width: 33.333333%;
    word-break: keep-all;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    color: #666;
}
.point-box .cont{
    color: #808080;
}
.point-box .price{
    color: #808080;
    text-align: center;
}
.point-box .time{
    color: #808080;
}
.point-box .title{
    text-align: center;
}

</style>